/**
 * Created by wangshaohua on 2018/1/25.
 */
moduleLearningMap.controller("LearningMapRouteQuery", function (LanguageService, $scope, $log, $state, GeneralResource, LoadingService, ConstantService, DialogService) {
    initPage($scope);
    $scope.$on("$viewContentLoaded", function () {
        $scope.reset();
        pageOnLoad($scope);
        ConstantService.addState($state.current, true, LanguageService.language('学习地图模版管理'));
        $scope.query(0);
    });

    $scope.reset = function () {
        $scope.queryPara = {
            className: Models.LearningMapRoute.className,
            query: {
                name: {
                    field: Models.LearningMapRoute.query.name
                }
            }
        };
    }

    $scope.query = function (pageNo) {
        //LoadingService.show();
        GeneralResource.queryPage({pageNo: pageNo - 1, pageSize: 10}, $scope.queryPara, function (queryResult) {
            $log.debug("查询结果", queryResult.data);
            $scope.queryResult = queryResult.data;
            $scope.pagination.setPage(queryResult.data, pageNo);
            //LoadingService.hide();
        });
    };
    $scope.pagination = new Pagination();
    $scope.pagination.setPageClickFn($scope.query);

    $scope.openDetail = function (record) {
        $state.go("sz.learningMapRouteDetail", {
            learningMapRouteId: record.id
        });
    }

    $scope.addDetail = function () {
        $state.go("sz.learningMapRouteDetail", {
            learningMapRouteId: null
        });
    }
    //$scope.query($scope.pagination.currentPageNo);

    //$scope.addStudyMap = function () {
    //    DialogService.open("addStudyMap");
    //};
    //
    //$scope.editStudyMap = function (studyMap) {
    //    $scope.currentStudyMap = studyMap;
    //    DialogService.open("editStudyMap", $scope);
    //};

    //$scope.setupClassGroup = function (studyMap) {
    //    ConstantService.setItem("currentStudyMapId", studyMap.id);
    //    $state.go("sz.studyMap.classGroup");
    //};
    //
    //$scope.toRoute = function (map) {
    //    $scope.currentStudyMap = map;
    //    DialogService.open("setStudyMapRoute", $scope);
    //};
    //
    //$scope.clearUserStudy = function (studyMap) {
    //    Alert.confirm("是否确认要执行该操作？", function () {
    //        var bean = {
    //            studyMapId: studyMap.id
    //        };
    //        UserStudyResource.clearForStudyMap(bean, {}, function () {
    //            $log.debug("清理用户信息");
    //            DialogService.close();
    //            Alert.success("清理用户信息成功！");
    //            //LoadingService.hide();
    //        });
    //    });
    //};
    //
    //$scope.clone = function(studyMap){
    //    Alert.confirm(function () {
    //        var bean = {
    //            studyMapId: studyMap.id
    //        };
    //        StudyMapResource.clone({}, bean, function () {
    //            $log.debug("清理用户信息");
    //            DialogService.close();
    //            Alert.success();
    //            //LoadingService.hide();
    //        });
    //    });
    //}
    //
    //$scope.updateProductStatus = function (map, productStatus) {
    //    var bean = {
    //        id: map.id,
    //        status: productStatus,
    //        type: "STUDY_MAP_ID"
    //    };
    //    ProductResource.updateStatus({}, bean, function () {
    //        $log.debug("更新产品状态");
    //        DialogService.close();
    //        Alert.success("更新产品状态成功！");
    //        //LoadingService.hide();
    //    }, function () {
    //        //LoadingService.hide();
    //    })
    //}
    //
    //$scope.refresh = function () {
    //    $scope.queryPara = {};
    //};
    //
    //$scope.toQRCode = function (map) {
    //    $scope.qrCodeBean = {
    //        id: map.id,
    //        fieldName: "STUDY_MAP_ID"
    //    };
    //    DialogService.open("productQRCode", $scope);
    //}
});